use warnings;
use Test::More tests => 105;
use Inline C;

#test part 1, add value 0
is(init(), 0, 'initialize the list, return LIST_OK(0).'); 
is(add_head(0), 0, 'add value 0, should LIST_OK(0).');
is(is_empty(), 0, 'the list should be not empty.');
is(get_head(), 0, 'now the head value should be 0.');
is(get_tail(), 0, 'now the tail value should be 0 too.');
is(get_length(), 1, 'now the length of the list should be 1.');
is(del_head(), 0, 'the deleted head value should be 0.');
is(is_empty(), 1, 'after delete, the list should be empty.');
is(get_length(), 0, 'after delete, the length of the list should be 0.');
is(get_head(), -2, 'after delete, the list should be LIST_EMP(-2).');
is(get_tail(), -2, 'after delete, the list should be LIST_EMP(-2).');
is(release(), -2, 'release the list, return value should be LIST_EMP(-2).');
is(is_empty(), 1, 'after release, the list should be empty.');
is(get_length(), 0, 'after release, the length of the list should be 0.');

#test part 2, add more values 0, 1, 2, 3, 4, 999, 10087, 233
is(add_head(0), 0, 'add value 0, should return LIST_OK(0).');
is(add_head(1), 0, 'add value 1, should return LIST_OK(0).');
is(add_head(2), 0, 'add value 2, should return LIST_OK(0).');
is(add_head(3), 0, 'add value 3, should return LIST_OK(0).');
is(add_head(4), 0, 'add value 4, should return LIST_OK(0).');
is(add_head(999), 0, 'add value 999, should return LIST_OK(0).');
is(add_head(10087), 0, 'add value 10087, should return LIST_OK(0).');
is(add_head(233), 0, 'add value 233, should return LIST_OK(0).');
is(get_length(), 8, 'after adding the 8 values, the length should be 8.');
is(get_head(), 233, 'now the head value should be 233.');
is(get_tail(), 0, 'now the tail value should be 0.');
is(del_head(), 233, 'the deleted head value should be 233.');
is(get_head(), 10087, 'after delete head, the head value should be 10087.');
is(del_head(), 10087, 'the deleted head value should be 10087.');
is(get_head(), 999, 'after delete head, the head value should be 999.');
is(del_head(), 999, 'the deleted head value should be 999.');
is(get_head(), 4, 'after delete head, the head value should be 4.');
is(get_length(), 5, 'after 3 times delete, the length should be 5.'); 
is(del_head(), 4, 'the deleted head value should be 4.');
is(del_head(), 3, 'the deleted head value should be 4.');
is(del_head(), 2, 'the deleted head value should be 4.');
is(del_head(), 1, 'the deleted head value should be 4.');
is(get_length(), 1, 'after 7 times delete, the length should be 1.'); 
is(get_head(), 0, 'now the head(how lonely) should be 0.');
is(get_tail(), 0, 'now the tail(only one item) should be 0 too.');
is(del_head(), 0, 'delete the last item that certainly should be 0.');
is(is_empty(), 1, 'now the list should be empty.');
is(get_length(), 0, 'the length should be 0.');
is(release(), -2, 'release the list, it should return LIST_EMP(-2).');

#test part 3, delete a value
is(add_head(0), 0, 'add value 0, should return LIST_OK(0).');
is(add_head(1), 0, 'add value 1, should return LIST_OK(0).');
is(add_head(2), 0, 'add value 2, should return LIST_OK(0).');
is(add_head(3), 0, 'add value 3, should return LIST_OK(0).');
is(add_head(4), 0, 'add value 4, should return LIST_OK(0).');
is(del(4), 4, 'delete 4, should return 4.');
is(get_head(), 3, 'after delete, the head value should be 3.');
is(del(1), 1, 'delete 1, should return 1.');
is(get_length(), 3, 'afete delete, the length should be 3.');
is(get_tail(), 0, 'the tail should be 0.');
is(del(0), 0, 'delete 0, should return 0.');
is(get_tail(), 2, 'the tail should be 2.');
is(get_head(), 3, 'the head should be 3.');
is(release(), 0, 'release the list, it should return LIST_OK(0).');

is(add_tail(0), 0, 'add value 0 to the tail of the list.');
is(add_tail(1), 0, 'add value 1 to the tail of the list.');
is(add_tail(2), 0, 'add value 2 to the tail of the list.');
is(add_tail(3), 0, 'add value 3 to the tail of the list.');
is(add_tail(4), 0, 'add value 4 to the tail of the list.');
is(add_tail(5), 0, 'add value 5 to the tail of the list.');
is(add_tail(6), 0, 'add value 6 to the tail of the list.');
is(add_tail(7), 0, 'add value 7 to the tail of the list.');
is(add_tail(8), 0, 'add value 8 to the tail of the list.');
is(add_tail(9), 0, 'add value 9 to the tail of the list.');
is(add_tail(10), 0, 'add value 10 to the tail of the list.');
is(add_tail(11), 0, 'add value 11 to the tail of the list.');
is(add_tail(12), 0, 'add value 12 to the tail of the list.');
is(add_tail(13), 0, 'add value 13 to the tail of the list.');
is(add_tail(14), 0, 'add value 14 to the tail of the list.');
is(add_tail(15), 0, 'add value 15 to the tail of the list.');
is(add_tail(16), 0, 'add value 16 to the tail of the list.');
is(add_tail(17), 0, 'add value 17 to the tail of the list.');

is(del(0), 0, 'del value 0 from the list.');
is(del(1), 1, 'del value 1 from the list.');
is(del(2), 2, 'del value 2 from the list.');
is(del(3), 3, 'del value 3 from the list.');
is(del(4), 4, 'del value 4 from the list.');
is(del(5), 5, 'del value 5 from the list.');
is(del(6), 6, 'del value 6 from the list.');
is(del(7), 7, 'del value 7 from the list.');
is(del(8), 8, 'del value 8 from the list.');
is(del(9), 9, 'del value 9 from the list.');
is(del(10), 10, 'del value 10 from the list.');
is(del(11), 11, 'del value 11 from the list.');
is(del(12), 12, 'del value 12 from the list.');
is(del(13), 13, 'del value 13 from the list.');
is(del(14), 14, 'del value 14 from the list.');
is(del(15), 15, 'del value 15 from the list.');
is(del(16), 16, 'del value 16 from the list.');
is(del(17), 17, 'del value 17 from the list.');
is(del(18), -1, 'no value 18 in the list.');
is(get_length(), 0, 'the list is empty now.');
is(get_head(), -2, 'as the list is emtpy, so no head.');
is(get_tail(), -2, 'as the list is emtpy, so no tail.');
is(is_empty(), 1, 'now the list is empty.');
is(del_head(), -2, 'try to delete head, but now the list is empty.');

is(release(), -2, 'release the list, but it has already been empty.');
is(is_empty(), 1, 'the list should be empty.');
is(get_head(), -2, 'now the list is empty.');
is(get_tail(), -2, 'now the list is empty.');
is(get_length(), 0, 'the length should be 0.');
is(del(0), -1, 'list is empty, no such value.');

__END__
__C__
#include <stdio.h>
#include <stdlib.h>
#include "../../../../mac/list.h"
#include "../../../../mac/list.c"
#include "list_test.c"

int init()
{
    return list_int_init();
}

int add_head(int value)
{
    return list_int_add_head(value);
}

int add_tail(int value)
{
    return list_int_add_tail(value);
}

int get_head()
{
    return list_int_get_head();
}

int get_tail()
{
    return list_int_get_tail();
}

int get_length()
{
    return list_int_get_length();
}

int release()
{
    return list_int_release();
}

int del_head()
{
    return list_int_del_head();
}

int is_empty()
{
    return list_int_is_empty();
}

int del(int value)
{
    return list_int_del(value);
}


